package com.gorkr;

import org.junit.jupiter.api.Test;

/**
 * @author gorkr
 * @date 2022/01/18 10:41
 **/
public class J24 {
    public ListNode reverseList(ListNode head) {
        ListNode pre = head, next = head.next, tmp;
        while(next!=null){
            tmp = next;
            next = next.next;
            tmp.next = pre;
            pre=tmp;
        }
        head.next=null;
        return pre;

    }

    @Test
    public void test(){
        ListNode a = new ListNode(1);
        ListNode b = new ListNode(2);
        ListNode c = new ListNode(3);
        ListNode d = new ListNode(4);
        a.next = b;
        b.next = c;
        c.next = d;

        reverseList(a);

    }
}
    